
const data0 = JSON.parse(localStorage.getItem("data"))
const data = data0.data
window.localStorage.removeItem('data')
salaryAdjustment=["员工转正","升职加薪"]
let dataId = Number(localStorage.getItem("id"));
function RenderBody(dataId) {
    for (let i = 0; i < data.length; ++i) {
        if (data[i].id === dataId) {
            $("#name").html(data[i].name)
            $("#type").html(data[i].type)
            $("#fixedSalary").val(data[i].fixedSalary)
            $("#meritPay").val(data[i].meritPay)
            $("#totalWages").val(data[i].fixedSalary + data[i].meritPay)
        }
    }
    list(salaryAdjustment)
}
function list(salaryAdjustment){
    for(let i = 0; i<salaryAdjustment.length;++i){
        $("#cause").append(` <option value="">${salaryAdjustment[i]}</option>`)
    }
}



$("#fixedSalary").on("input",function(){
    $("#totalWages").val(Number($("#fixedSalary").val()) + Number( $("#meritPay").val()) )
})

$("#meritPay").on("input",function(){
    $("#totalWages").val(Number($("#fixedSalary").val()) + Number( $("#meritPay").val()) )
})

$("#submit").on("click",function(){
    for (let i = 0; i < data.length; ++i) {
        if (data[i].id === dataId) {
            data[i].fixedSalary =$("#fixedSalary").val()
            data[i].meritPay =$("#meritPay").val()
            data[i].disabled =$("#disabled").val()
            data[i].totalWages =$("#totalWages").val()
        }
    }
    window.localStorage.removeItem('id')
    localStorage.setItem("data", JSON.stringify({data}));
    window.location.href = "../薪资/薪资.html"

})


$("#cancel").on("click",function(){
    window.location.href = "../薪资/薪资.html"
    window.localStorage.removeItem('id')
})


RenderBody(dataId)

